from datetime import datetime
from django.db.models import When, Case, Value, IntegerField
from django.http import JsonResponse
from .models import *
from django.views.decorators.csrf import csrf_exempt


# Create your views here.


@csrf_exempt
def message(x):
    return JsonResponse({'message': x})


@csrf_exempt
def user_information(x):
    return JsonResponse(
        {
            'message': 'success',
            'username': x.username,
            'phone_number': x.phone_number,
            'password': x.password,
            'email': x.email,
            'real_name': x.real_name
        }
    )


@csrf_exempt
def project_information_kept(x):
    return {
        'project_name': x.project_name,
        'team_name': x.team_belong_to.team_name,
        'created_time': x.created_time,
        'project_creator': x.project_creator.username,
        'description': x.description,
        'update_time': x.update_time,
        'if_kept': "yes"
    }


@csrf_exempt
def project_information_not_kept(x):
    return {
        'project_name': x.project_name,
        'team_name': x.team_belong_to.team_name,
        'created_time': x.created_time,
        'project_creator': x.project_creator.username,
        'description': x.description,
        'update_time': x.update_time,
        'if_kept': "no"
    }


@csrf_exempt
def project_information(x):
    return {
        'project_name': x.project_name,
        'team_name': x.team_belong_to.team_name,
        'created_time': x.created_time,
        'project_creator': x.project_creator.username,
        'description': x.description,
        'update_time': x.update_time,
    }


@csrf_exempt
def document_information(x):
    return {
        'document_name': x.document_name,
        'creator': x.document_creator.username,
        'project_belong_to': x.project_belong_to.project_name,
        'team_belong_to': x.team_belong_to.team_name,
        'created_time': x.created_time,
        'update_time': x.update_time,
        'type': x.type
    }


@csrf_exempt
def prototype_information(x):
    return {
        'prototype_name': x.name,
        'creator': x.creator.username,
        'project_belong_to': x.project_belong_to.project_name,
        'team_belong_to': x.team_belong_to.team_name,
        'created_time': x.created_time,
        'update_time': x.update_time,
        'type': x.type
    }


def team_information(x):
    return {
        'message': 'success',
        'team_name': x.team_name
    }


@csrf_exempt
def user_information_more(x, y):
    membership = LinkBetweenTeamAndMember.objects.filter(team_member=x, team=y).first().membership
    return {
        'message': 'success',
        'username': x.username,
        'phone_number': x.phone_number,
        'membership': membership,
        'email': x.email,
        'real_name': x.real_name
    }


def notice_to_content(notice):
    sender = notice.sender
    receiver = notice.receiver
    content = {
        'sender_name': sender.username,
        'receiver_name': receiver.username,
        'datetime': notice.send_time,
        'content': notice.content,
        'type': notice.type
    }
    return content


@csrf_exempt
def login(request):
    if request.method != 'POST':
        return message('fail')
    else:
        username = request.POST.get('username')
        password = request.POST.get('password')
        phone_number = request.POST.get('phone_number')
        user = User.objects.filter(username=username).first()
        if user is not None:
            if user.password == password:
                return user_information(user)
        user = User.objects.filter(phone_number=phone_number).first()
        if user is not None:
            if user.password == password:
                return user_information(user)
        return message('账号或密码错误')


@csrf_exempt
def register(request):
    if request.method != 'POST':
        return message('fail')
    user_of_same_name = User.objects.filter(username=request.POST.get('username')).first()
    user_of_same_phone_number = User.objects.filter(phone_number=request.POST.get('phone_number')).first()
    if user_of_same_name is not None or user_of_same_phone_number is not None:
        return message('用户已存在')
    else:
        new_user = User(username=request.POST.get('username'),
                        password=request.POST.get('password'),
                        phone_number=request.POST.get('phone_number'),
                        real_name=request.POST.get('real_name'))
        new_user.save()
        return message('success')


@csrf_exempt
def team_create(request):
    if request.method != 'POST':
        return message('fail')
    else:
        user = User.objects.filter(username=request.POST.get('username')).first()
        team_name = request.POST.get('team_name')
        team_of_same_name = Team.objects.filter(team_name=team_name).first()
        if team_of_same_name is not None:
            return message('队伍已存在')
        new_team = Team(team_name=team_name, owner=user)
        new_team.save()
        new_team_member = LinkBetweenTeamAndMember(team=new_team, team_member=user, membership='superManager')
        new_team_member.save()
        new_project = Project(created_time=datetime.datetime.now(),
                              project_creator=user,
                              team_belong_to=new_team,
                              project_name='部门介绍',
                              description='部门介绍',
                              update_time=datetime.datetime.now(),
                              recyclable=False,
                              flag='abnormal'
                              )
        new_project.save()
        new_project1 = Project(created_time=datetime.datetime.now(),
                               project_creator=user,
                               team_belong_to=new_team,
                               project_name='相关数据',
                               description='相关数据',
                               update_time=datetime.datetime.now(),
                               recyclable=False,
                               flag='abnormal'
                               )
        new_project1.save()
        new_project2 = Project(created_time=datetime.datetime.now(),
                               project_creator=user,
                               team_belong_to=new_team,
                               project_name='其他文档',
                               description='其他文档',
                               update_time=datetime.datetime.now(),
                               recyclable=False,
                               flag='abnormal'
                               )
        new_project2.save()
        return message('success')


@csrf_exempt
def team_delete(request):
    if request.method != 'POST':
        return message('fail')
    else:
        user = User.objects.filter(username=request.POST.get('username')).first()
        team = Team.objects.filter(team_name=request.POST.get('team_name')).first()
        if team.owner != user:
            return message('false')
        team_members = LinkBetweenTeamAndMember.objects.filter(team=team)
        for team_member in team_members:
            member = team_member.team_member
            new_notice = Notice(sender=user, receiver=member,
                                content=user.username + "已将团队(" + team.team_name + ")解散",
                                team=team, send_time=datetime.datetime.now(), type='deleteTeam')
            new_notice.save()
            team_member.delete()
        team.delete()
        return message('success')


@csrf_exempt
def remove_user(request):
    if request.method != 'POST':
        return message('fail')
    user = User.objects.filter(username=request.POST.get('username')).first()
    team = Team.objects.filter(team_name=request.POST.get('team_name')).first()
    membership = LinkBetweenTeamAndMember.objects.filter(team=team, team_member=user).first().membership
    if membership != 'superManager' and membership != 'generalManager':
        return message('权限不足')
    user_to_remove = User.objects.filter(username=request.POST.get('user_to_remove')).first()
    membership1 = LinkBetweenTeamAndMember.objects.filter(team=team,
                                                          team_member=user_to_remove).first().membership
    if membership == 'generalManager' and membership1 != 'staff':
        return message('权限不足')
    if membership == 'generalManager' and membership1 != 'generalManager':
        return message('创建者不可把自己移出团队')
    LinkBetweenTeamAndMember.objects.filter(team=team, team_member=user_to_remove).first().delete()
    new_notice = Notice(sender=user, receiver=user_to_remove,
                        content=user.username + "将你从团队(" + team.team_name + ")中移除",
                        team=team, send_time=datetime.datetime.now(), type='deleteUser')
    new_notice.save()
    return message('success')


@csrf_exempt
def modify_membership(request):
    if request.method != 'POST':
        return message('fail')
    team = Team.objects.filter(team_name=request.POST.get('team_name')).first()
    user_to_modify = User.objects.filter(username=request.POST.get('user_to_modify')).first()
    membership = LinkBetweenTeamAndMember.objects.filter(team=team,
                                                         team_member=user_to_modify).first().membership
    if membership == 'superManager':
        return message('不可修改创建者身份')
    membership1 = request.POST.get('modify_to')
    if membership1 != 'generalManager' and membership1 != 'staff':
        return message('权限不足')
    member = LinkBetweenTeamAndMember.objects.filter(team_member=user_to_modify, team=team).first()
    member.membership = membership1
    member.save()
    new_notice = Notice(sender=team.owner, receiver=user_to_modify,
                        content=team.owner.username + "将你设为团队(" + team.team_name + ")的" + membership1,
                        team=team, send_time=datetime.datetime.now(), type='modifyMembership')
    new_notice.save()
    return message('success')


@csrf_exempt
def team_member(request):
    if request.method != 'POST':
        return message('fail')
    team = Team.objects.filter(team_name=request.POST.get('team_name')).first()
    if team is None:
        return message('队伍不存在')
    res = []
    members = LinkBetweenTeamAndMember.objects.filter(team=team)
    for member in members:
        user = member.team_member
        res.append(user_information_more(user, team))
    return JsonResponse(res, safe=False)


@csrf_exempt
def team(request):
    if request.method != 'POST':
        return message('fail')
    user = User.objects.filter(username=request.POST.get('username')).first()
    if user is None:
        return message('用户不存在')
    res = []
    members = LinkBetweenTeamAndMember.objects.filter(team_member=user)
    for member in members:
        team = member.team
        res.append(team_information(team))
    return JsonResponse(res, safe=False)


@csrf_exempt
def invite_user(request):
    if request.method != 'POST':
        return message('fail')
    sender = User.objects.filter(username=request.POST.get('username')).first()
    team = Team.objects.filter(team_name=request.POST.get('team_name')).first()
    receiver = User.objects.filter(username=request.POST.get('user_to_invite')).first()
    membership = LinkBetweenTeamAndMember.objects.filter(team=team, team_member=sender).first().membership
    member = LinkBetweenTeamAndMember.objects.filter(team=team, team_member=receiver).first()
    if member is not None:
        return message('该用户已在团队中')
    if membership != 'superManager' and membership != 'generalManager':
        return message('权限不足')
    new_notice = Notice(content=sender.username + "邀请你加入团队(" + team.team_name + ")", sender=sender, receiver=receiver,
                        team=team, send_time=datetime.datetime.now(), type='invite')
    new_notice.save()
    return message('success')


@csrf_exempt
def invite_accept(request):
    if request.method != 'POST':
        return message('fail')
    user = User.objects.filter(username=request.POST.get('username')).first()
    team = Team.objects.filter(team_name=request.POST.get('team_name')).first()
    new_team_member = LinkBetweenTeamAndMember(team=team, team_member=user, membership='staff')
    new_team_member.save()
    return message('success')


@csrf_exempt
def quit_team(request):
    if request.method != 'POST':
        return message('fail')
    team = Team.objects.filter(team_name=request.POST.get('team_name')).first()
    user = User.objects.filter(username=request.POST.get('username')).first()
    if team.owner == user:
        return message('队长不可退出团队')
    LinkBetweenTeamAndMember.objects.filter(team=team, team_member=user).first().delete()
    return message('success')


@csrf_exempt
def create_project(request):
    if request.method != 'POST':
        return message('fail')

    creator_name = request.POST.get('username')
    project_creator = User.objects.filter(username=creator_name).first()
    if project_creator is None:
        return message('用户不存在')

    team_name = request.POST.get('team_name')
    team_belong_to = Team.objects.filter(team_name=team_name).first()
    if team_belong_to is None:
        return message('团队不存在')

    project_name = request.POST.get('project_name')
    project_of_the_same_name = Project.objects.filter(project_name=project_name,
                                                      team_belong_to=team_belong_to).first()
    if project_of_the_same_name is not None:
        if project_of_the_same_name.recyclable:
            return message('该项目在回收站中')
        return message('该项目已存在')

    description = request.POST.get('description')
    created_time = datetime.datetime.now()

    new_project = Project(created_time=created_time,
                          project_creator=project_creator,
                          team_belong_to=team_belong_to,
                          project_name=project_name,
                          description=description,
                          update_time=created_time,
                          recyclable=False,
                          flag='normal'
                          )
    new_project.save()

    # new_prototype = Prototype(
    #     name='prototype',
    #     creator=project_creator,
    #     created_time=created_time,
    #     content=' ',
    #     project_belong_to=new_project,
    #     team_belong_to=team_belong_to,
    #     update_time=created_time,
    #     recyclable=False
    # )
    # new_prototype.save()
    return message('success')


@csrf_exempt
def change_project_information(request):
    if request.method != 'POST':
        return message('fail')

    team_name = request.POST.get('team_name')
    team_belong_to = Team.objects.filter(team_name=team_name).first()
    if team_belong_to is None:
        return message('团队不存在')

    project_name = request.POST.get('project_name')
    project = Project.objects.filter(project_name=project_name, team_belong_to=team_belong_to).first()
    if project is None:
        return message('项目不存在')
    if project.flag == 'abnormal':
        return message('fail')
    else:
        new_project_name = request.POST.get('new_project_name')
        new_description = request.POST.get('new_description')
        project_of_the_same_name = Project.objects.filter(project_name=new_project_name,
                                                          team_belong_to=team_belong_to).first()
        if project_of_the_same_name is not None:
            if project_of_the_same_name.recyclable:
                return message('该项目在回收站中')
            return message('该项目已存在')
        else:
            project.update_time = datetime.datetime.now()
            project.project_name = new_project_name
            project.description = new_description
            project.save()
            return message('success')


@csrf_exempt
def delete_project(request):
    if request.method != 'POST':
        return message('fail')

    team_name = request.POST.get('team_name')
    team_belong_to = Team.objects.filter(team_name=team_name).first()
    if team_belong_to is None:
        return message('团队不存在')

    project_name = request.POST.get('project_name')
    project = Project.objects.filter(project_name=project_name, team_belong_to=team_belong_to,
                                     flag='normal').first()
    if project is None:
        return message('项目不存在')
    else:
        project.delete()
        return message('success')


@csrf_exempt
def get_all_projects(request):
    username = request.POST.get('username')
    user = User.objects.filter(username=username).first()
    if user is None:
        return message('用户不存在')

    team_name = request.POST.get('team_name')
    team = Team.objects.filter(team_name=team_name).first()
    if team is None:
        return message('团队不存在')
    projects = Project.objects.filter(team_belong_to=team, flag='normal').order_by('-update_time')
    res = []
    for i in projects:
        if i.recyclable == False:
            j = KeptProject.objects.filter(user=user, project=i).first()
            if j is not None:
                res.append(project_information_kept(i))
            else:
                res.append(project_information_not_kept(i))
    return JsonResponse(res, safe=False)


@csrf_exempt
def create_document(request):
    if request.method != 'POST':
        return message('fail')

    creator_name = request.POST.get('creator_name')
    project_name = request.POST.get('project_name')
    team_name = request.POST.get('team_name')
    document_name = request.POST.get('document_name')
    type = request.POST.get('type')
    created_time = datetime.datetime.now()

    creator = User.objects.filter(username=creator_name).first()
    if creator is None:
        return message('用户不存在')

    team = Team.objects.filter(team_name=team_name).first()
    if team is None:
        return message('团队不存在')

    project = Project.objects.filter(team_belong_to=team, project_name=project_name).first()
    if project is None:
        return message('项目不存在')

    duplicated_document = Document.objects.filter(document_name=document_name, team_belong_to=team,
                                                  project_belong_to=project).first()
    if duplicated_document is not None:
        return message('该文档已存在')
    else:
        new_document = Document(
            document_name=document_name,
            team_belong_to=team,
            project_belong_to=project,
            document_creator=creator,
            created_time=created_time,
            update_time=created_time,
            recyclable=False,
            type=type
        )
        new_document.save()
        project.update_time = datetime.datetime.now()
        project.save()
        return message('success')


@csrf_exempt
def save_document(request):
    if request.method != 'POST':
        return message('fail')

    project_name = request.POST.get('project_name')
    team_name = request.POST.get('team_name')
    document_name = request.POST.get('document_name')
    content = request.POST.get('content')

    team = Team.objects.filter(team_name=team_name).first()
    if team is None:
        return message('团队不存在')

    project = Project.objects.filter(team_belong_to=team, project_name=project_name).first()
    if project is None:
        return message('项目不存在')

    document = Document.objects.filter(team_belong_to=team, project_belong_to=project,
                                       document_name=document_name).first()
    if document is None:
        return message('文档不存在')

    document.update_time = datetime.datetime.now()
    document.content = content
    document.save()
    project.update_time = datetime.datetime.now()
    project.save()
    return message('success')


@csrf_exempt
def get_all_documents(request):
    project_name = request.POST.get('project_name')
    team_name = request.POST.get('team_name')

    team = Team.objects.filter(team_name=team_name).first()
    if team is None:
        return message('团队不存在')

    project = Project.objects.filter(team_belong_to=team, project_name=project_name).first()
    if project is None:
        return message('项目不存在')

    documents = Document.objects.filter(team_belong_to=team, project_belong_to=project)
    res = []
    for i in documents:
        if i.recyclable == False:
            res.append(document_information(i))
    return JsonResponse(res, safe=False)


@csrf_exempt
def get_document_content(request):
    project_name = request.POST.get('project_name')
    team_name = request.POST.get('team_name')
    document_name = request.POST.get('document_name')

    team = Team.objects.filter(team_name=team_name).first()
    if team is None:
        return message('团队不存在')

    project = Project.objects.filter(team_belong_to=team, project_name=project_name).first()
    if project is None:
        return message('项目不存在')

    document = Document.objects.filter(team_belong_to=team, project_belong_to=project,
                                       document_name=document_name).first()
    if document is None:
        return message('文档不存在')

    res = {
        'message': 'success',
        'content': document.content
    }
    return JsonResponse(res, safe=False)


@csrf_exempt
def change_document_information(request):
    if request.method != 'POST':
        return message('fail')

    project_name = request.POST.get('project_name')
    team_name = request.POST.get('team_name')
    document_name = request.POST.get('document_name')
    new_name = request.POST.get('new_name')

    team = Team.objects.filter(team_name=team_name).first()
    if team is None:
        return message('团队不存在')

    project = Project.objects.filter(team_belong_to=team, project_name=project_name).first()
    if project is None:
        return message('项目不存在')

    document = Document.objects.filter(team_belong_to=team, project_belong_to=project,
                                       document_name=document_name).first()
    if document is None:
        return message('文档不存在')

    document.document_name = new_name
    document.update_time = datetime.datetime.now()
    document.save()
    project.update_time = datetime.datetime.now()
    project.save()
    return message('success')


@csrf_exempt
def change_password(request):
    username = request.POST.get('username')
    old_password = request.POST.get('old_password')
    new_password = request.POST.get('new_password')

    user = User.objects.filter(username=username).first()
    if user is None:
        return message('用户不存在')

    if user.password == old_password:
        user.password = new_password
        user.save()
        return message('success')
    else:
        return message('输入旧密码错误')


@csrf_exempt
def change_user_information(request):
    username = request.POST.get('username')
    new_email = request.POST.get('new_email')
    new_phone_number = request.POST.get('new_phone_number')

    user = User.objects.filter(username=username).first()
    if user is None:
        return message('用户不存在')
    else:
        user.email = new_email
        user.phone_number = new_phone_number
        user.save()
        return message('success')


@csrf_exempt
def invite_without_notice(request):
    if request.method != 'POST':
        return message('fail')
    sender = User.objects.filter(username=request.POST.get('username')).first()
    team = Team.objects.filter(team_name=request.POST.get('team_name')).first()
    receiver = User.objects.filter(username=request.POST.get('user_to_invite')).first()
    if receiver is None:
        return message('用户不存在')
    membership = LinkBetweenTeamAndMember.objects.filter(team=team, team_member=sender).first().membership
    member = LinkBetweenTeamAndMember.objects.filter(team=team, team_member=receiver).first()
    if member is not None:
        return message('该用户已在团队中')
    if membership != 'superManager' and membership != 'generalManager':
        return message('权限不足')
    new_team_member = LinkBetweenTeamAndMember(team=team, team_member=receiver, membership='staff')
    new_team_member.save()
    team_members = LinkBetweenTeamAndMember.objects.filter(team=team)
    for members in team_members:
        member = members.team_member
        new_notice = Notice(sender=receiver, receiver=member,
                            content=receiver.username + "加入了团队(" + team.team_name + ")",
                            team=team, send_time=datetime.datetime.now(), type='invite')
        new_notice.save()
    return message('success')


@csrf_exempt
def user_info(request):
    if request.method != 'POST':
        return message('fail')
    user = User.objects.filter(username=request.POST.get('username')).first()
    return JsonResponse(
        {
            'message': 'success',
            'username': user.username,
            'phone_number': user.phone_number,
            'password': user.password,
            'email': user.email,
            'real_name': user.real_name
        }
    )


@csrf_exempt
def create_prototype(request):
    if request.method != 'POST':
        return message('fail')

    creator_name = request.POST.get('creator_name')
    project_name = request.POST.get('project_name')
    team_name = request.POST.get('team_name')
    prototype_name = request.POST.get('prototype_name')
    type = request.POST.get('type')
    created_time = datetime.datetime.now()

    s = [
        "[{\"attribute\":[{\"key\":\"width\",\"name\":\"宽度(px)\",\"value\":\"300\",\"type\":\"input\",\"placeholder\":\"请输入宽度\"},{\"key\":\"height\",\"name\":\"长度(px)\",\"value\":\"600\",\"type\":\"input\",\"placeholder\":\"请输入长度\"},{\"key\":\"transform\",\"name\":\"旋转角度\",\"value\":\"0\",\"type\":\"input\",\"placeholder\":\"请输入旋转角度\"},{\"key\":\"opacity\",\"name\":\"不透明度(0-1)\",\"value\":\"1\",\"type\":\"input\",\"placeholder\":\"请输入不透明度\"},{\"key\":\"border_width\",\"name\":\"边框宽度(px)\",\"value\":\"3\",\"type\":\"input\",\"placeholder\":\"请选择颜色\"},{\"key\":\"border_color\",\"name\":\"边框颜色\",\"value\":\"#000\",\"type\":\"color\",\"placeholder\":\"请选择颜色\"}],\"data\":\"ddd\",\"template\":\"<recComp width=300   height=600   transform=0   opacity=1   border_width=3   border_color=#000     data='ddd'></recComp>\",\"info\":{\"name\":\"矩形组件\",\"type\":\"recComp\",\"id\":\"a5e0e993-a6fe\"},\"position\":{\"left\":381,\"top\":21,\"zIndex\":1}},{\"attribute\":[{\"key\":\"width\",\"name\":\"宽度(px)\",\"value\":\"300\",\"type\":\"input\",\"placeholder\":\"请输入宽度\"},{\"key\":\"transform\",\"name\":\"旋转角度\",\"value\":\"0\",\"type\":\"input\",\"placeholder\":\"请输入旋转角度\"},{\"key\":\"opacity\",\"name\":\"不透明度(0-1)\",\"value\":\"0.1\",\"type\":\"input\",\"placeholder\":\"请输入不透明度\"},{\"key\":\"border_color\",\"name\":\"边框颜色\",\"value\":\"#000\",\"type\":\"color\",\"placeholder\":\"请选择颜色\"}],\"data\":\"ddd\",\"template\":\"<lineComp width=300   transform=0   opacity=0.1   border_color=#000     data='ddd'></lineComp>\",\"info\":{\"name\":\"直线组件\",\"type\":\"lineComp\",\"id\":\"4ac68b5d-8be0\"},\"position\":{\"left\":382,\"top\":39,\"zIndex\":2}},{\"attribute\":[{\"key\":\"width\",\"name\":\"宽度(px)\",\"value\":\"100\",\"type\":\"input\",\"placeholder\":\"请输入宽度\"},{\"key\":\"height\",\"name\":\"高度(px)\",\"value\":\"10\",\"type\":\"input\",\"placeholder\":\"请输入高度\"},{\"key\":\"fontSize\",\"name\":\"字体大小(px)\",\"value\":\"10\",\"type\":\"input\",\"placeholder\":\"请输入字体大小\"},{\"key\":\"fontWeight\",\"name\":\"字体粗细(px)\",\"value\":\"400\",\"type\":\"input\",\"placeholder\":\"请输入字体粗细\"},{\"key\":\"letterSpacing\",\"name\":\"字间距(px)\",\"value\":\"4\",\"type\":\"input\",\"placeholder\":\"请输入字间距\"},{\"key\":\"color\",\"name\":\"文本颜色\",\"value\":\"#000000\",\"type\":\"color\",\"placeholder\":\"请选择颜色\"},{\"key\":\"background_color\",\"name\":\"背景颜色\",\"value\":\"#eeeeee\",\"type\":\"color\",\"placeholder\":\"请选择颜色\"}],\"data\":\"21:00\",\"template\":\"<textComp width=100   height=10   fontSize=10   fontWeight=400   letterSpacing=4   color=#000000   background_color=#eeeeee     data='21:00'></textComp>\",\"info\":{\"name\":\"文本组件\",\"type\":\"textComp\",\"id\":\"c992e87a-2090\"},\"position\":{\"left\":482,\"top\":26,\"zIndex\":3}},{\"attribute\":[{\"key\":\"width\",\"name\":\"宽度(px)\",\"value\":\"300\",\"type\":\"input\",\"placeholder\":\"请输入宽度\"},{\"key\":\"transform\",\"name\":\"旋转角度\",\"value\":\"0\",\"type\":\"input\",\"placeholder\":\"请输入旋转角度\"},{\"key\":\"opacity\",\"name\":\"不透明度(0-1)\",\"value\":\"1\",\"type\":\"input\",\"placeholder\":\"请输入不透明度\"},{\"key\":\"border_color\",\"name\":\"边框颜色\",\"value\":\"#000\",\"type\":\"color\",\"placeholder\":\"请选择颜色\"}],\"data\":\"ddd\",\"template\":\"<lineComp width=300   transform=0   opacity=1   border_color=#000     data='ddd'></lineComp>\",\"info\":{\"name\":\"直线组件\",\"type\":\"lineComp\",\"id\":\"a011d5e2-cdd1\"},\"position\":{\"left\":380,\"top\":562,\"zIndex\":4}},{\"attribute\":[{\"key\":\"width\",\"name\":\"宽度(px)\",\"value\":\"60\",\"type\":\"input\",\"placeholder\":\"请输入宽度\"},{\"key\":\"transform\",\"name\":\"旋转角度\",\"value\":\"90\",\"type\":\"input\",\"placeholder\":\"请输入旋转角度\"},{\"key\":\"opacity\",\"name\":\"不透明度(0-1)\",\"value\":\"1\",\"type\":\"input\",\"placeholder\":\"请输入不透明度\"},{\"key\":\"border_color\",\"name\":\"边框颜色\",\"value\":\"#000\",\"type\":\"color\",\"placeholder\":\"请选择颜色\"}],\"data\":\"ddd\",\"template\":\"<lineComp width=60   transform=90   opacity=1   border_color=#000     data='ddd'></lineComp>\",\"info\":{\"name\":\"直线组件\",\"type\":\"lineComp\",\"id\":\"fa7cad83-93d1\"},\"position\":{\"left\":449,\"top\":593,\"zIndex\":5}},{\"attribute\":[{\"key\":\"width\",\"name\":\"宽度(px)\",\"value\":\"60\",\"type\":\"input\",\"placeholder\":\"请输入宽度\"},{\"key\":\"transform\",\"name\":\"旋转角度\",\"value\":\"90\",\"type\":\"input\",\"placeholder\":\"请输入旋转角度\"},{\"key\":\"opacity\",\"name\":\"不透明度(0-1)\",\"value\":\"1\",\"type\":\"input\",\"placeholder\":\"请输入不透明度\"},{\"key\":\"border_color\",\"name\":\"边框颜色\",\"value\":\"#000\",\"type\":\"color\",\"placeholder\":\"请选择颜色\"}],\"data\":\"ddd\",\"template\":\"<lineComp width=60   transform=90   opacity=1   border_color=#000     data='ddd'></lineComp>\",\"info\":{\"name\":\"直线组件\",\"type\":\"lineComp\",\"id\":\"c2a87a3a-c63f\"},\"position\":{\"left\":557,\"top\":594,\"zIndex\":6}},{\"attribute\":[{\"key\":\"width\",\"name\":\"宽度(px)\",\"value\":\"100\",\"type\":\"input\",\"placeholder\":\"请输入宽度\"},{\"key\":\"height\",\"name\":\"高度(px)\",\"value\":\"40\",\"type\":\"input\",\"placeholder\":\"请输入高度\"},{\"key\":\"fontSize\",\"name\":\"字体大小(px)\",\"value\":\"14\",\"type\":\"input\",\"placeholder\":\"请输入字体大小\"},{\"key\":\"fontWeight\",\"name\":\"字体粗细(px)\",\"value\":\"400\",\"type\":\"input\",\"placeholder\":\"请输入字体粗细\"},{\"key\":\"letterSpacing\",\"name\":\"字间距(px)\",\"value\":\"4\",\"type\":\"input\",\"placeholder\":\"请输入字间距\"},{\"key\":\"color\",\"name\":\"文本颜色\",\"value\":\"#eeeeee\",\"type\":\"color\",\"placeholder\":\"请选择颜色\"},{\"key\":\"background_color\",\"name\":\"背景颜色\",\"value\":\"#eeeeee\",\"type\":\"color\",\"placeholder\":\"请选择颜色\"}],\"data\":\"\",\"template\":\"<textComp width=100   height=40   fontSize=14   fontWeight=400   letterSpacing=4   color=#eeeeee   background_color=#eeeeee     data='示例文字'></textComp>\",\"info\":{\"name\":\"文本组件\",\"type\":\"textComp\",\"id\":\"7ac90acb-8ab0\"},\"position\":{\"left\":124,\"top\":305,\"zIndex\":7}},{\"attribute\":[{\"key\":\"width\",\"name\":\"宽度(px)\",\"value\":\"75\",\"type\":\"input\",\"placeholder\":\"请输入宽度\"},{\"key\":\"height\",\"name\":\"高度(px)\",\"value\":\"40\",\"type\":\"input\",\"placeholder\":\"请输入高度\"},{\"key\":\"fontSize\",\"name\":\"字体大小(px)\",\"value\":\"26\",\"type\":\"input\",\"placeholder\":\"请输入字体大小\"},{\"key\":\"fontWeight\",\"name\":\"字体粗细(px)\",\"value\":\"1000\",\"type\":\"input\",\"placeholder\":\"请输入字体粗细\"},{\"key\":\"letterSpacing\",\"name\":\"字间距(px)\",\"value\":\"4\",\"type\":\"input\",\"placeholder\":\"请输入字间距\"},{\"key\":\"color\",\"name\":\"文本颜色\",\"value\":\"#1e61e6\",\"type\":\"color\",\"placeholder\":\"请选择颜色\"},{\"key\":\"background_color\",\"name\":\"背景颜色\",\"value\":\"#eeeeee\",\"type\":\"color\",\"placeholder\":\"请选择颜色\"}],\"data\":\"首页\",\"template\":\"<textComp width=75   height=40   fontSize=26   fontWeight=1000   letterSpacing=4   color=#1e61e6   background_color=#eeeeee     data='首页'></textComp>\",\"info\":{\"name\":\"文本组件\",\"type\":\"textComp\",\"id\":\"8a8f08b6-0d3c\"},\"position\":{\"left\":393,\"top\":577,\"zIndex\":8}},{\"attribute\":[{\"key\":\"width\",\"name\":\"宽度(px)\",\"value\":\"75\",\"type\":\"input\",\"placeholder\":\"请输入宽度\"},{\"key\":\"height\",\"name\":\"高度(px)\",\"value\":\"40\",\"type\":\"input\",\"placeholder\":\"请输入高度\"},{\"key\":\"fontSize\",\"name\":\"字体大小(px)\",\"value\":\"26\",\"type\":\"input\",\"placeholder\":\"请输入字体大小\"},{\"key\":\"fontWeight\",\"name\":\"字体粗细(px)\",\"value\":\"1000\",\"type\":\"input\",\"placeholder\":\"请输入字体粗细\"},{\"key\":\"letterSpacing\",\"name\":\"字间距(px)\",\"value\":\"4\",\"type\":\"input\",\"placeholder\":\"请输入字间距\"},{\"key\":\"color\",\"name\":\"文本颜色\",\"value\":\"#000000\",\"type\":\"color\",\"placeholder\":\"请选择颜色\"},{\"key\":\"background_color\",\"name\":\"背景颜色\",\"value\":\"#eeeeee\",\"type\":\"color\",\"placeholder\":\"请选择颜色\"}],\"data\":\"动态\",\"template\":\"<textComp width=75   height=40   fontSize=26   fontWeight=1000   letterSpacing=4   color=#000000   background_color=#eeeeee     data='动态'></textComp>\",\"info\":{\"name\":\"文本组件\",\"type\":\"textComp\",\"id\":\"aa293b48-cbaa\"},\"position\":{\"left\":500,\"top\":577,\"zIndex\":9}},{\"attribute\":[{\"key\":\"width\",\"name\":\"宽度(px)\",\"value\":\"75\",\"type\":\"input\",\"placeholder\":\"请输入宽度\"},{\"key\":\"height\",\"name\":\"高度(px)\",\"value\":\"40\",\"type\":\"input\",\"placeholder\":\"请输入高度\"},{\"key\":\"fontSize\",\"name\":\"字体大小(px)\",\"value\":\"26\",\"type\":\"input\",\"placeholder\":\"请输入字体大小\"},{\"key\":\"fontWeight\",\"name\":\"字体粗细(px)\",\"value\":\"1000\",\"type\":\"input\",\"placeholder\":\"请输入字体粗细\"},{\"key\":\"letterSpacing\",\"name\":\"字间距(px)\",\"value\":\"4\",\"type\":\"input\",\"placeholder\":\"请输入字间距\"},{\"key\":\"color\",\"name\":\"文本颜色\",\"value\":\"#000000\",\"type\":\"color\",\"placeholder\":\"请选择颜色\"},{\"key\":\"background_color\",\"name\":\"背景颜色\",\"value\":\"#eeeeee\",\"type\":\"color\",\"placeholder\":\"请选择颜色\"}],\"data\":\"设置\",\"template\":\"<textComp width=75   height=40   fontSize=26   fontWeight=1000   letterSpacing=4   color=#000000   background_color=#eeeeee     data='设置'></textComp>\",\"info\":{\"name\":\"文本组件\",\"type\":\"textComp\",\"id\":\"fecf6ab0-62f6\"},\"position\":{\"left\":601,\"top\":577,\"zIndex\":10}},{\"attribute\":[{\"key\":\"width\",\"name\":\"宽度(px)\",\"value\":\"200\",\"type\":\"input\",\"placeholder\":\"请输入宽度\"},{\"key\":\"height\",\"name\":\"高度(px)\",\"value\":\"25\",\"type\":\"input\",\"placeholder\":\"请输入高度\"},{\"key\":\"fontSize\",\"name\":\"字体大小(px)\",\"value\":\"20\",\"type\":\"input\",\"placeholder\":\"请输入字体大小\"},{\"key\":\"fontWeight\",\"name\":\"字体粗细(px)\",\"value\":\"800\",\"type\":\"input\",\"placeholder\":\"请输入字体粗细\"},{\"key\":\"letterSpacing\",\"name\":\"字间距(px)\",\"value\":\"75\",\"type\":\"input\",\"placeholder\":\"请输入字间距\"},{\"key\":\"color\",\"name\":\"文本颜色\",\"value\":\"#000000\",\"type\":\"color\",\"placeholder\":\"请选择颜色\"},{\"key\":\"background_color\",\"name\":\"背景颜色\",\"value\":\"#eeeeee\",\"type\":\"color\",\"placeholder\":\"请选择颜色\"}],\"data\":\"首页\",\"template\":\"<textComp width=200   height=25   fontSize=20   fontWeight=800   letterSpacing=75   color=#000000   background_color=#eeeeee     data='首页'></textComp>\",\"info\":{\"name\":\"文本组件\",\"type\":\"textComp\",\"id\":\"fefe1d28-a091\"},\"position\":{\"left\":467,\"top\":47,\"zIndex\":11}},{\"attribute\":[{\"key\":\"width\",\"name\":\"宽度(px)\",\"value\":\"300\",\"type\":\"input\",\"placeholder\":\"请输入宽度\"},{\"key\":\"transform\",\"name\":\"旋转角度\",\"value\":\"0\",\"type\":\"input\",\"placeholder\":\"请输入旋转角度\"},{\"key\":\"opacity\",\"name\":\"不透明度(0-1)\",\"value\":\"1\",\"type\":\"input\",\"placeholder\":\"请输入不透明度\"},{\"key\":\"border_color\",\"name\":\"边框颜色\",\"value\":\"#000\",\"type\":\"color\",\"placeholder\":\"请选择颜色\"}],\"data\":\"ddd\",\"template\":\"<lineComp width=300   transform=0   opacity=1   border_color=#000     data='ddd'></lineComp>\",\"info\":{\"name\":\"直线组件\",\"type\":\"lineComp\",\"id\":\"b7f8aa27-563c\"},\"position\":{\"left\":382,\"top\":78,\"zIndex\":12}},{\"attribute\":[{\"key\":\"width\",\"name\":\"宽度(px)\",\"value\":\"60\",\"type\":\"input\",\"placeholder\":\"请输入宽度\"},{\"key\":\"height\",\"name\":\"高度(px)\",\"value\":\"40\",\"type\":\"input\",\"placeholder\":\"请输入高度\"},{\"key\":\"fontSize\",\"name\":\"字体大小(px)\",\"value\":\"14\",\"type\":\"input\",\"placeholder\":\"请输入字体大小\"},{\"key\":\"fontWeight\",\"name\":\"字体粗细(px)\",\"value\":\"1000\",\"type\":\"input\",\"placeholder\":\"请输入字体粗细\"},{\"key\":\"letterSpacing\",\"name\":\"字间距(px)\",\"value\":\"4\",\"type\":\"input\",\"placeholder\":\"请输入字间距\"},{\"key\":\"color\",\"name\":\"文本颜色\",\"value\":\"#000000\",\"type\":\"color\",\"placeholder\":\"请选择颜色\"},{\"key\":\"background_color\",\"name\":\"背景颜色\",\"value\":\"#eeeeee\",\"type\":\"color\",\"placeholder\":\"请选择颜色\"}],\"data\":\"频道1\",\"template\":\"<textComp width=60   height=40   fontSize=14   fontWeight=1000   letterSpacing=4   color=#000000   background_color=#eeeeee     data='频道1'></textComp>\",\"info\":{\"name\":\"文本组件\",\"type\":\"textComp\",\"id\":\"8cf543a8-8ca3\"},\"position\":{\"left\":392,\"top\":89,\"zIndex\":13}},{\"attribute\":[{\"key\":\"width\",\"name\":\"宽度(px)\",\"value\":\"60\",\"type\":\"input\",\"placeholder\":\"请输入宽度\"},{\"key\":\"height\",\"name\":\"高度(px)\",\"value\":\"40\",\"type\":\"input\",\"placeholder\":\"请输入高度\"},{\"key\":\"fontSize\",\"name\":\"字体大小(px)\",\"value\":\"14\",\"type\":\"input\",\"placeholder\":\"请输入字体大小\"},{\"key\":\"fontWeight\",\"name\":\"字体粗细(px)\",\"value\":\"400\",\"type\":\"input\",\"placeholder\":\"请输入字体粗细\"},{\"key\":\"letterSpacing\",\"name\":\"字间距(px)\",\"value\":\"4\",\"type\":\"input\",\"placeholder\":\"请输入字间距\"},{\"key\":\"color\",\"name\":\"文本颜色\",\"value\":\"#000000\",\"type\":\"color\",\"placeholder\":\"请选择颜色\"},{\"key\":\"background_color\",\"name\":\"背景颜色\",\"value\":\"#eeeeee\",\"type\":\"color\",\"placeholder\":\"请选择颜色\"}],\"data\":\"频道2\",\"template\":\"<textComp width=60   height=40   fontSize=14   fontWeight=400   letterSpacing=4   color=#000000   background_color=#eeeeee     data='频道2'></textComp>\",\"info\":{\"name\":\"文本组件\",\"type\":\"textComp\",\"id\":\"274c7106-8640\"},\"position\":{\"left\":470,\"top\":89,\"zIndex\":14}},{\"attribute\":[{\"key\":\"width\",\"name\":\"宽度(px)\",\"value\":\"60\",\"type\":\"input\",\"placeholder\":\"请输入宽度\"},{\"key\":\"height\",\"name\":\"高度(px)\",\"value\":\"40\",\"type\":\"input\",\"placeholder\":\"请输入高度\"},{\"key\":\"fontSize\",\"name\":\"字体大小(px)\",\"value\":\"14\",\"type\":\"input\",\"placeholder\":\"请输入字体大小\"},{\"key\":\"fontWeight\",\"name\":\"字体粗细(px)\",\"value\":\"400\",\"type\":\"input\",\"placeholder\":\"请输入字体粗细\"},{\"key\":\"letterSpacing\",\"name\":\"字间距(px)\",\"value\":\"4\",\"type\":\"input\",\"placeholder\":\"请输入字间距\"},{\"key\":\"color\",\"name\":\"文本颜色\",\"value\":\"#000000\",\"type\":\"color\",\"placeholder\":\"请选择颜色\"},{\"key\":\"background_color\",\"name\":\"背景颜色\",\"value\":\"#eeeeee\",\"type\":\"color\",\"placeholder\":\"请选择颜色\"}],\"data\":\"频道3\",\"template\":\"<textComp width=60   height=40   fontSize=14   fontWeight=400   letterSpacing=4   color=#000000   background_color=#eeeeee     data='频道3'></textComp>\",\"info\":{\"name\":\"文本组件\",\"type\":\"textComp\",\"id\":\"7e374a13-7483\"},\"position\":{\"left\":546,\"top\":89,\"zIndex\":15}},{\"attribute\":[{\"key\":\"width\",\"name\":\"宽度(px)\",\"value\":\"60\",\"type\":\"input\",\"placeholder\":\"请输入宽度\"},{\"key\":\"height\",\"name\":\"高度(px)\",\"value\":\"40\",\"type\":\"input\",\"placeholder\":\"请输入高度\"},{\"key\":\"fontSize\",\"name\":\"字体大小(px)\",\"value\":\"14\",\"type\":\"input\",\"placeholder\":\"请输入字体大小\"},{\"key\":\"fontWeight\",\"name\":\"字体粗细(px)\",\"value\":\"400\",\"type\":\"input\",\"placeholder\":\"请输入字体粗细\"},{\"key\":\"letterSpacing\",\"name\":\"字间距(px)\",\"value\":\"4\",\"type\":\"input\",\"placeholder\":\"请输入字间距\"},{\"key\":\"color\",\"name\":\"文本颜色\",\"value\":\"#000000\",\"type\":\"color\",\"placeholder\":\"请选择颜色\"},{\"key\":\"background_color\",\"name\":\"背景颜色\",\"value\":\"#eeeeee\",\"type\":\"color\",\"placeholder\":\"请选择颜色\"}],\"data\":\"频道4\",\"template\":\"<textComp width=60   height=40   fontSize=14   fontWeight=400   letterSpacing=4   color=#000000   background_color=#eeeeee     data='频道4'></textComp>\",\"info\":{\"name\":\"文本组件\",\"type\":\"textComp\",\"id\":\"da2d9d87-f503\"},\"position\":{\"left\":616,\"top\":88,\"zIndex\":16}},{\"attribute\":[{\"key\":\"width\",\"name\":\"宽度(px)\",\"value\":\"230\",\"type\":\"input\",\"placeholder\":\"请输入宽度\"},{\"key\":\"transform\",\"name\":\"旋转角度\",\"value\":\"0\",\"type\":\"input\",\"placeholder\":\"请输入旋转角度\"},{\"key\":\"opacity\",\"name\":\"不透明度(0-1)\",\"value\":\"1\",\"type\":\"input\",\"placeholder\":\"请输入不透明度\"},{\"key\":\"border_color\",\"name\":\"边框颜色\",\"value\":\"#000\",\"type\":\"color\",\"placeholder\":\"请选择颜色\"}],\"data\":\"ddd\",\"template\":\"<lineComp width=230   transform=0   opacity=1   border_color=#000     data='ddd'></lineComp>\",\"info\":{\"name\":\"直线组件\",\"type\":\"lineComp\",\"id\":\"b3ac3cec-ab3c\"},\"position\":{\"left\":451,\"top\":118,\"zIndex\":17}},{\"attribute\":[{\"key\":\"width\",\"name\":\"宽度(px)\",\"value\":\"70\",\"type\":\"input\",\"placeholder\":\"请输入宽度\"},{\"key\":\"transform\",\"name\":\"旋转角度\",\"value\":\"0\",\"type\":\"input\",\"placeholder\":\"请输入旋转角度\"},{\"key\":\"opacity\",\"name\":\"不透明度(0-1)\",\"value\":\"1\",\"type\":\"input\",\"placeholder\":\"请输入不透明度\"},{\"key\":\"border_color\",\"name\":\"边框颜色\",\"value\":\"#e9078b\",\"type\":\"color\",\"placeholder\":\"请选择颜色\"}],\"data\":\"ddd\",\"template\":\"<lineComp width=70   transform=0   opacity=1   border_color=#e9078b     data='ddd'></lineComp>\",\"info\":{\"name\":\"直线组件\",\"type\":\"lineComp\",\"id\":\"edba96f3-551a\"},\"position\":{\"left\":380,\"top\":118,\"zIndex\":18}},{\"attribute\":[{\"key\":\"width\",\"name\":\"宽度(px)\",\"value\":\"100\",\"type\":\"input\",\"placeholder\":\"请输入宽度\"},{\"key\":\"height\",\"name\":\"长度(px)\",\"value\":\"100\",\"type\":\"input\",\"placeholder\":\"请输入长度\"},{\"key\":\"transform\",\"name\":\"旋转角度\",\"value\":\"0\",\"type\":\"input\",\"placeholder\":\"请输入旋转角度\"},{\"key\":\"opacity\",\"name\":\"不透明度(0-1)\",\"value\":\"0.5\",\"type\":\"input\",\"placeholder\":\"请输入不透明度\"},{\"key\":\"border_width\",\"name\":\"边框宽度(px)\",\"value\":\"3\",\"type\":\"input\",\"placeholder\":\"请选择颜色\"},{\"key\":\"border_color\",\"name\":\"边框颜色\",\"value\":\"#000\",\"type\":\"color\",\"placeholder\":\"请选择颜色\"}],\"data\":\"ddd\",\"template\":\"<recComp width=100   height=100   transform=0   opacity=0.5   border_width=3   border_color=#000     data='ddd'></recComp>\",\"info\":{\"name\":\"矩形组件\",\"type\":\"recComp\",\"id\":\"062ef377-aa2f\"},\"position\":{\"left\":414,\"top\":148,\"zIndex\":19}},{\"attribute\":[{\"key\":\"width\",\"name\":\"宽度(px)\",\"value\":\"100\",\"type\":\"input\",\"placeholder\":\"请输入宽度\"},{\"key\":\"height\",\"name\":\"长度(px)\",\"value\":\"100\",\"type\":\"input\",\"placeholder\":\"请输入长度\"},{\"key\":\"transform\",\"name\":\"旋转角度\",\"value\":\"0\",\"type\":\"input\",\"placeholder\":\"请输入旋转角度\"},{\"key\":\"opacity\",\"name\":\"不透明度(0-1)\",\"value\":\"0.5\",\"type\":\"input\",\"placeholder\":\"请输入不透明度\"},{\"key\":\"border_width\",\"name\":\"边框宽度(px)\",\"value\":\"3\",\"type\":\"input\",\"placeholder\":\"请选择颜色\"},{\"key\":\"border_color\",\"name\":\"边框颜色\",\"value\":\"#000\",\"type\":\"color\",\"placeholder\":\"请选择颜色\"}],\"data\":\"ddd\",\"template\":\"<recComp width=100   height=100   transform=0   opacity=0.5   border_width=3   border_color=#000     data='ddd'></recComp>\",\"info\":{\"name\":\"矩形组件\",\"type\":\"recComp\",\"id\":\"0bac332b-8570\"},\"position\":{\"left\":554,\"top\":149,\"zIndex\":20}},{\"attribute\":[{\"key\":\"width\",\"name\":\"宽度(px)\",\"value\":\"200\",\"type\":\"input\",\"placeholder\":\"请输入宽度\"},{\"key\":\"transform\",\"name\":\"旋转角度\",\"value\":\"0\",\"type\":\"input\",\"placeholder\":\"请输入旋转角度\"},{\"key\":\"opacity\",\"name\":\"不透明度(0-1)\",\"value\":\"1\",\"type\":\"input\",\"placeholder\":\"请输入不透明度\"},{\"key\":\"border_color\",\"name\":\"边框颜色\",\"value\":\"#eeeeee\",\"type\":\"color\",\"placeholder\":\"请选择颜色\"}],\"data\":\"ddd\",\"template\":\"<lineComp width=200   transform=0   opacity=1   border_color=#eeeeee     data='ddd'></lineComp>\",\"info\":{\"name\":\"直线组件\",\"type\":\"lineComp\",\"id\":\"2bc2b084-d2ae\"},\"position\":{\"left\":103,\"top\":281,\"zIndex\":21}},{\"attribute\":[{\"key\":\"width\",\"name\":\"宽度(px)\",\"value\":\"100\",\"type\":\"input\",\"placeholder\":\"请输入宽度\"},{\"key\":\"height\",\"name\":\"长度(px)\",\"value\":\"100\",\"type\":\"input\",\"placeholder\":\"请输入长度\"},{\"key\":\"transform\",\"name\":\"旋转角度\",\"value\":\"0\",\"type\":\"input\",\"placeholder\":\"请输入旋转角度\"},{\"key\":\"opacity\",\"name\":\"不透明度(0-1)\",\"value\":\"0.5\",\"type\":\"input\",\"placeholder\":\"请输入不透明度\"},{\"key\":\"border_width\",\"name\":\"边框宽度(px)\",\"value\":\"3\",\"type\":\"input\",\"placeholder\":\"请选择颜色\"},{\"key\":\"border_color\",\"name\":\"边框颜色\",\"value\":\"#000\",\"type\":\"color\",\"placeholder\":\"请选择颜色\"}],\"data\":\"ddd\",\"template\":\"<recComp width=100   height=100   transform=0   opacity=0.5   border_width=3   border_color=#000     data='ddd'></recComp>\",\"info\":{\"name\":\"矩形组件\",\"type\":\"recComp\",\"id\":\"71ae5121-b26d\"},\"position\":{\"left\":416,\"top\":285,\"zIndex\":22}},{\"attribute\":[{\"key\":\"width\",\"name\":\"宽度(px)\",\"value\":\"100\",\"type\":\"input\",\"placeholder\":\"请输入宽度\"},{\"key\":\"height\",\"name\":\"长度(px)\",\"value\":\"100\",\"type\":\"input\",\"placeholder\":\"请输入长度\"},{\"key\":\"transform\",\"name\":\"旋转角度\",\"value\":\"0\",\"type\":\"input\",\"placeholder\":\"请输入旋转角度\"},{\"key\":\"opacity\",\"name\":\"不透明度(0-1)\",\"value\":\"0.5\",\"type\":\"input\",\"placeholder\":\"请输入不透明度\"},{\"key\":\"border_width\",\"name\":\"边框宽度(px)\",\"value\":\"3\",\"type\":\"input\",\"placeholder\":\"请选择颜色\"},{\"key\":\"border_color\",\"name\":\"边框颜色\",\"value\":\"#000\",\"type\":\"color\",\"placeholder\":\"请选择颜色\"}],\"data\":\"ddd\",\"template\":\"<recComp width=100   height=100   transform=0   opacity=0.5   border_width=3   border_color=#000     data='ddd'></recComp>\",\"info\":{\"name\":\"矩形组件\",\"type\":\"recComp\",\"id\":\"2d20a1ed-4aa7\"},\"position\":{\"left\":555,\"top\":284,\"zIndex\":23}},{\"attribute\":[{\"key\":\"width\",\"name\":\"宽度(px)\",\"value\":\"100\",\"type\":\"input\",\"placeholder\":\"请输入宽度\"},{\"key\":\"height\",\"name\":\"长度(px)\",\"value\":\"100\",\"type\":\"input\",\"placeholder\":\"请输入长度\"},{\"key\":\"transform\",\"name\":\"旋转角度\",\"value\":\"0\",\"type\":\"input\",\"placeholder\":\"请输入旋转角度\"},{\"key\":\"opacity\",\"name\":\"不透明度(0-1)\",\"value\":\"0.5\",\"type\":\"input\",\"placeholder\":\"请输入不透明度\"},{\"key\":\"border_width\",\"name\":\"边框宽度(px)\",\"value\":\"3\",\"type\":\"input\",\"placeholder\":\"请选择颜色\"},{\"key\":\"border_color\",\"name\":\"边框颜色\",\"value\":\"#000\",\"type\":\"color\",\"placeholder\":\"请选择颜色\"}],\"data\":\"ddd\",\"template\":\"<recComp width=100   height=100   transform=0   opacity=0.5   border_width=3   border_color=#000     data='ddd'></recComp>\",\"info\":{\"name\":\"矩形组件\",\"type\":\"recComp\",\"id\":\"59ab7444-bcdb\"},\"position\":{\"left\":417,\"top\":421,\"zIndex\":24}},{\"attribute\":[{\"key\":\"width\",\"name\":\"宽度(px)\",\"value\":\"100\",\"type\":\"input\",\"placeholder\":\"请输入宽度\"},{\"key\":\"height\",\"name\":\"长度(px)\",\"value\":\"100\",\"type\":\"input\",\"placeholder\":\"请输入长度\"},{\"key\":\"transform\",\"name\":\"旋转角度\",\"value\":\"0\",\"type\":\"input\",\"placeholder\":\"请输入旋转角度\"},{\"key\":\"opacity\",\"name\":\"不透明度(0-1)\",\"value\":\"0.5\",\"type\":\"input\",\"placeholder\":\"请输入不透明度\"},{\"key\":\"border_width\",\"name\":\"边框宽度(px)\",\"value\":\"3\",\"type\":\"input\",\"placeholder\":\"请选择颜色\"},{\"key\":\"border_color\",\"name\":\"边框颜色\",\"value\":\"#000\",\"type\":\"color\",\"placeholder\":\"请选择颜色\"}],\"data\":\"ddd\",\"template\":\"<recComp width=100   height=100   transform=0   opacity=0.5   border_width=3   border_color=#000     data='ddd'></recComp>\",\"info\":{\"name\":\"矩形组件\",\"type\":\"recComp\",\"id\":\"bca2f8c0-1e29\"},\"position\":{\"left\":556,\"top\":421,\"zIndex\":25}},{\"attribute\":[{\"key\":\"width\",\"name\":\"宽度\",\"value\":\"80\",\"type\":\"input\",\"placeholder\":\"请输入宽度(px)\"},{\"key\":\"height\",\"name\":\"高度\",\"value\":\"80\",\"type\":\"input\",\"placeholder\":\"请输入高度(px)\"},{\"key\":\"transform\",\"name\":\"旋转角度\",\"value\":\"0\",\"type\":\"input\",\"placeholder\":\"请输入旋转角度\"},{\"key\":\"opacity\",\"name\":\"不透明度(0-1)\",\"value\":\"0.2\",\"type\":\"input\",\"placeholder\":\"请输入不透明度\"}],\"data\":\"https://gimg2.baidu.com/image_search/src=http%3A%2F%2Fpic.51yuansu.com%2Fpic3%2Fcover%2F02%2F20%2F71%2F59afc66b8fed7_610.jpg&refer=http%3A%2F%2Fpic.51yuansu.com&app=2002&size=f9999,10000&q=a80&n=0&g=0n&fmt=auto?sec=1662654997&t=fabc048996029c6ec2862566443626a6\",\"template\":\"<picComp width=80   height=80   transform=0   opacity=0.2     data='https://gimg2.baidu.com/image_search/src=http%3A%2F%2Fpic.51yuansu.com%2Fpic3%2Fcover%2F02%2F20%2F71%2F59afc66b8fed7_610.jpg&refer=http%3A%2F%2Fpic.51yuansu.com&app=2002&size=f9999,10000&q=a80&n=0&g=0n&fmt=auto?sec=1662654997&t=fabc048996029c6ec2862566443626a6'></picComp>\",\"info\":{\"name\":\"图片组件\",\"type\":\"picComp\",\"id\":\"c09000ef-4e01\"},\"position\":{\"left\":426,\"top\":163,\"zIndex\":26}}]",
        "[{\"attribute\":[{\"key\":\"width\",\"name\":\"宽度(px)\",\"value\":\"800\",\"type\":\"input\",\"placeholder\":\"请输入宽度\"},{\"key\":\"height\",\"name\":\"长度(px)\",\"value\":\"500\",\"type\":\"input\",\"placeholder\":\"请输入长度\"},{\"key\":\"transform\",\"name\":\"旋转角度\",\"value\":\"0\",\"type\":\"input\",\"placeholder\":\"请输入旋转角度\"},{\"key\":\"opacity\",\"name\":\"不透明度(0-1)\",\"value\":\"1\",\"type\":\"input\",\"placeholder\":\"请输入不透明度\"},{\"key\":\"border_width\",\"name\":\"边框宽度(px)\",\"value\":\"3\",\"type\":\"input\",\"placeholder\":\"请选择颜色\"},{\"key\":\"border_color\",\"name\":\"边框颜色\",\"value\":\"#000\",\"type\":\"color\",\"placeholder\":\"请选择颜色\"}],\"data\":\"ddd\",\"template\":\"<recComp width=800   height=500   transform=0   opacity=1   border_width=3   border_color=#000     data='ddd'></recComp>\",\"info\":{\"name\":\"矩形组件\",\"type\":\"recComp\",\"id\":\"1f052302-03f0\"},\"position\":{\"left\":141,\"top\":78,\"zIndex\":1}},{\"attribute\":[{\"key\":\"width\",\"name\":\"宽度\",\"value\":\"50\",\"type\":\"input\",\"placeholder\":\"请输入宽度(px)\"},{\"key\":\"height\",\"name\":\"高度\",\"value\":\"50\",\"type\":\"input\",\"placeholder\":\"请输入高度(px)\"},{\"key\":\"transform\",\"name\":\"旋转角度\",\"value\":\"0\",\"type\":\"input\",\"placeholder\":\"请输入旋转角度\"},{\"key\":\"opacity\",\"name\":\"不透明度(0-1)\",\"value\":\"0.2\",\"type\":\"input\",\"placeholder\":\"请输入不透明度\"}],\"data\":\"https://gimg2.baidu.com/image_search/src=http%3A%2F%2Fpic.51yuansu.com%2Fpic3%2Fcover%2F02%2F20%2F71%2F59afc66b8fed7_610.jpg&refer=http%3A%2F%2Fpic.51yuansu.com&app=2002&size=f9999,10000&q=a80&n=0&g=0n&fmt=auto?sec=1662654997&t=fabc048996029c6ec2862566443626a6\",\"template\":\"<picComp width=50   height=50   transform=0   opacity=0.2     data='https://gimg2.baidu.com/image_search/src=http%3A%2F%2Fpic.51yuansu.com%2Fpic3%2Fcover%2F02%2F20%2F71%2F59afc66b8fed7_610.jpg&refer=http%3A%2F%2Fpic.51yuansu.com&app=2002&size=f9999,10000&q=a80&n=0&g=0n&fmt=auto?sec=1662654997&t=fabc048996029c6ec2862566443626a6'></picComp>\",\"info\":{\"name\":\"图片组件\",\"type\":\"picComp\",\"id\":\"04d55c6d-201f\"},\"position\":{\"left\":150,\"top\":88,\"zIndex\":2}},{\"attribute\":[{\"key\":\"width\",\"name\":\"宽度(px)\",\"value\":\"800\",\"type\":\"input\",\"placeholder\":\"请输入宽度\"},{\"key\":\"transform\",\"name\":\"旋转角度\",\"value\":\"0\",\"type\":\"input\",\"placeholder\":\"请输入旋转角度\"},{\"key\":\"opacity\",\"name\":\"不透明度(0-1)\",\"value\":\"0.3\",\"type\":\"input\",\"placeholder\":\"请输入不透明度\"},{\"key\":\"border_color\",\"name\":\"边框颜色\",\"value\":\"#000\",\"type\":\"color\",\"placeholder\":\"请选择颜色\"}],\"data\":\"ddd\",\"template\":\"<lineComp width=800   transform=0   opacity=0.3   border_color=#000     data='ddd'></lineComp>\",\"info\":{\"name\":\"直线组件\",\"type\":\"lineComp\",\"id\":\"38fc1fe7-3334\"},\"position\":{\"left\":143,\"top\":146,\"zIndex\":3}},{\"attribute\":[{\"key\":\"width\",\"name\":\"宽度(px)\",\"value\":\"430\",\"type\":\"input\",\"placeholder\":\"请输入宽度\"},{\"key\":\"transform\",\"name\":\"旋转角度\",\"value\":\"90\",\"type\":\"input\",\"placeholder\":\"请输入旋转角度\"},{\"key\":\"opacity\",\"name\":\"不透明度(0-1)\",\"value\":\"0.3\",\"type\":\"input\",\"placeholder\":\"请输入不透明度\"},{\"key\":\"border_color\",\"name\":\"边框颜色\",\"value\":\"#000\",\"type\":\"color\",\"placeholder\":\"请选择颜色\"}],\"data\":\"ddd\",\"template\":\"<lineComp width=430   transform=90   opacity=0.3   border_color=#000     data='ddd'></lineComp>\",\"info\":{\"name\":\"直线组件\",\"type\":\"lineComp\",\"id\":\"13102f67-836e\"},\"position\":{\"left\":32,\"top\":365,\"zIndex\":4}},{\"attribute\":[{\"key\":\"width\",\"name\":\"宽度(px)\",\"value\":\"500\",\"type\":\"input\",\"placeholder\":\"请输入宽度\"},{\"key\":\"height\",\"name\":\"高度(px)\",\"value\":\"40\",\"type\":\"input\",\"placeholder\":\"请输入高度\"},{\"key\":\"fontSize\",\"name\":\"字体大小(px)\",\"value\":\"28\",\"type\":\"input\",\"placeholder\":\"请输入字体大小\"},{\"key\":\"fontWeight\",\"name\":\"字体粗细(px)\",\"value\":\"1000\",\"type\":\"input\",\"placeholder\":\"请输入字体粗细\"},{\"key\":\"letterSpacing\",\"name\":\"字间距(px)\",\"value\":\"16\",\"type\":\"input\",\"placeholder\":\"请输入字间距\"},{\"key\":\"color\",\"name\":\"文本颜色\",\"value\":\"#0e1ce1\",\"type\":\"color\",\"placeholder\":\"请选择颜色\"},{\"key\":\"background_color\",\"name\":\"背景颜色\",\"value\":\"#eeeeee\",\"type\":\"color\",\"placeholder\":\"请选择颜色\"}],\"data\":\"xxx管理系统\",\"template\":\"<textComp width=500   height=40   fontSize=28   fontWeight=1000   letterSpacing=16   color=#0e1ce1   background_color=#eeeeee     data='xxx管理系统'></textComp>\",\"info\":{\"name\":\"文本组件\",\"type\":\"textComp\",\"id\":\"11d4faa6-08e3\"},\"position\":{\"left\":303,\"top\":92,\"zIndex\":5}},{\"attribute\":[{\"key\":\"width\",\"name\":\"宽度(px)\",\"value\":\"100\",\"type\":\"input\",\"placeholder\":\"请输入宽度\"},{\"key\":\"height\",\"name\":\"高度(px)\",\"value\":\"40\",\"type\":\"input\",\"placeholder\":\"请输入高度\"},{\"key\":\"fontSize\",\"name\":\"字体大小(px)\",\"value\":\"22\",\"type\":\"input\",\"placeholder\":\"请输入字体大小\"},{\"key\":\"fontWeight\",\"name\":\"字体粗细(px)\",\"value\":\"600\",\"type\":\"input\",\"placeholder\":\"请输入字体粗细\"},{\"key\":\"letterSpacing\",\"name\":\"字间距(px)\",\"value\":\"4\",\"type\":\"input\",\"placeholder\":\"请输入字间距\"},{\"key\":\"color\",\"name\":\"文本颜色\",\"value\":\"#c80000\",\"type\":\"color\",\"placeholder\":\"请选择颜色\"},{\"key\":\"background_color\",\"name\":\"背景颜色\",\"value\":\"#eeeeee\",\"type\":\"color\",\"placeholder\":\"请选择颜色\"}],\"data\":\"退出\",\"template\":\"<textComp width=100   height=40   fontSize=22   fontWeight=600   letterSpacing=4   color=#c80000   background_color=#eeeeee     data='退出'></textComp>\",\"info\":{\"name\":\"文本组件\",\"type\":\"textComp\",\"id\":\"7d21ef69-2e58\"},\"position\":{\"left\":841,\"top\":96,\"zIndex\":6}},{\"attribute\":[{\"key\":\"width\",\"name\":\"宽度(px)\",\"value\":\"100\",\"type\":\"input\",\"placeholder\":\"请输入宽度\"},{\"key\":\"transform\",\"name\":\"旋转角度\",\"value\":\"0\",\"type\":\"input\",\"placeholder\":\"请输入旋转角度\"},{\"key\":\"opacity\",\"name\":\"不透明度(0-1)\",\"value\":\"0.1\",\"type\":\"input\",\"placeholder\":\"请输入不透明度\"},{\"key\":\"border_color\",\"name\":\"边框颜色\",\"value\":\"#000\",\"type\":\"color\",\"placeholder\":\"请选择颜色\"}],\"data\":\"ddd\",\"template\":\"<lineComp width=100   transform=0   opacity=0.1   border_color=#000     data='ddd'></lineComp>\",\"info\":{\"name\":\"直线组件\",\"type\":\"lineComp\",\"id\":\"56fa72ea-9997\"},\"position\":{\"left\":142,\"top\":217,\"zIndex\":7}},{\"attribute\":[{\"key\":\"width\",\"name\":\"宽度(px)\",\"value\":\"100\",\"type\":\"input\",\"placeholder\":\"请输入宽度\"},{\"key\":\"transform\",\"name\":\"旋转角度\",\"value\":\"0\",\"type\":\"input\",\"placeholder\":\"请输入旋转角度\"},{\"key\":\"opacity\",\"name\":\"不透明度(0-1)\",\"value\":\"0.1\",\"type\":\"input\",\"placeholder\":\"请输入不透明度\"},{\"key\":\"border_color\",\"name\":\"边框颜色\",\"value\":\"#000\",\"type\":\"color\",\"placeholder\":\"请选择颜色\"}],\"data\":\"ddd\",\"template\":\"<lineComp width=100   transform=0   opacity=0.1   border_color=#000     data='ddd'></lineComp>\",\"info\":{\"name\":\"直线组件\",\"type\":\"lineComp\",\"id\":\"6ac851d2-1d0f\"},\"position\":{\"left\":145,\"top\":293,\"zIndex\":8}},{\"attribute\":[{\"key\":\"width\",\"name\":\"宽度(px)\",\"value\":\"100\",\"type\":\"input\",\"placeholder\":\"请输入宽度\"},{\"key\":\"transform\",\"name\":\"旋转角度\",\"value\":\"0\",\"type\":\"input\",\"placeholder\":\"请输入旋转角度\"},{\"key\":\"opacity\",\"name\":\"不透明度(0-1)\",\"value\":\"0.1\",\"type\":\"input\",\"placeholder\":\"请输入不透明度\"},{\"key\":\"border_color\",\"name\":\"边框颜色\",\"value\":\"#000\",\"type\":\"color\",\"placeholder\":\"请选择颜色\"}],\"data\":\"ddd\",\"template\":\"<lineComp width=100   transform=0   opacity=0.1   border_color=#000     data='ddd'></lineComp>\",\"info\":{\"name\":\"直线组件\",\"type\":\"lineComp\",\"id\":\"82b74b57-7d8f\"},\"position\":{\"left\":145,\"top\":374,\"zIndex\":9}},{\"attribute\":[{\"key\":\"width\",\"name\":\"宽度(px)\",\"value\":\"100\",\"type\":\"input\",\"placeholder\":\"请输入宽度\"},{\"key\":\"transform\",\"name\":\"旋转角度\",\"value\":\"0\",\"type\":\"input\",\"placeholder\":\"请输入旋转角度\"},{\"key\":\"opacity\",\"name\":\"不透明度(0-1)\",\"value\":\"0.1\",\"type\":\"input\",\"placeholder\":\"请输入不透明度\"},{\"key\":\"border_color\",\"name\":\"边框颜色\",\"value\":\"#000\",\"type\":\"color\",\"placeholder\":\"请选择颜色\"}],\"data\":\"ddd\",\"template\":\"<lineComp width=100   transform=0   opacity=0.1   border_color=#000     data='ddd'></lineComp>\",\"info\":{\"name\":\"直线组件\",\"type\":\"lineComp\",\"id\":\"65a5e71e-276b\"},\"position\":{\"left\":145,\"top\":463,\"zIndex\":10}}]"
    ]

    creator = User.objects.filter(username=creator_name).first()
    if creator is None:
        return message('用户不存在')

    team = Team.objects.filter(team_name=team_name).first()
    if team is None:
        return message('团队不存在')

    project = Project.objects.filter(team_belong_to=team, project_name=project_name, flag='normal').first()
    if project is None:
        return message('项目不存在')

    duplicated_prototype = Prototype.objects.filter(name=prototype_name, team_belong_to=team,
                                                    project_belong_to=project).first()
    if duplicated_prototype is not None:
        return message('该原型已存在')
    else:
        if(type == '无模板'):
            new_prototype = Prototype(
                name=prototype_name,
                team_belong_to=team,
                project_belong_to=project,
                creator=creator,
                created_time=created_time,
                update_time=created_time,
                recyclable=False,
                type=type
            )
            new_prototype.save()
        elif(type == 'APP'):
            new_prototype = Prototype(
                name=prototype_name,
                team_belong_to=team,
                project_belong_to=project,
                creator=creator,
                content=s[0],
                created_time=created_time,
                update_time=created_time,
                recyclable=False,
                type=type
            )
            new_prototype.save()
        elif (type == '管理系统'):
            new_prototype = Prototype(
                name=prototype_name,
                team_belong_to=team,
                project_belong_to=project,
                creator=creator,
                content=s[1],
                created_time=created_time,
                update_time=created_time,
                recyclable=False,
                type=type
            )
            new_prototype.save()
        return message('success')


@csrf_exempt
def save_prototype(request):
    if request.method != 'POST':
        return message('fail')

    project_name = request.POST.get('project_name')
    team_name = request.POST.get('team_name')
    prototype_name = request.POST.get('prototype_name')
    content = request.POST.get('content')

    team = Team.objects.filter(team_name=team_name).first()
    if team is None:
        return message('团队不存在')

    project = Project.objects.filter(team_belong_to=team, project_name=project_name, flag='normal').first()
    if project is None:
        return message('项目不存在')

    prototype = Prototype.objects.filter(team_belong_to=team, project_belong_to=project,
                                         name=prototype_name).first()
    if prototype is None:
        return message('原型不存在')

    prototype.update_time = datetime.datetime.now()
    prototype.content = content
    prototype.save()
    return message('success')


@csrf_exempt
def change_prototype_information(request):
    if request.method != 'POST':
        return message('fail')

    project_name = request.POST.get('project_name')
    team_name = request.POST.get('team_name')
    prototype_name = request.POST.get('prototype_name')
    new_name = request.POST.get('new_name')

    team = Team.objects.filter(team_name=team_name).first()
    if team is None:
        return message('团队不存在')

    project = Project.objects.filter(team_belong_to=team, project_name=project_name, flag='normal').first()
    if project is None:
        return message('项目不存在')

    prototype = Prototype.objects.filter(team_belong_to=team, project_belong_to=project,
                                         name=prototype_name).first()
    if prototype is None:
        return message('原型不存在')

    prototype.document_name = new_name
    prototype.update_time = datetime.datetime.now()
    prototype.save()
    return message('success')


@csrf_exempt
def get_all_prototypes(request):
    project_name = request.POST.get('project_name')
    team_name = request.POST.get('team_name')

    team = Team.objects.filter(team_name=team_name).first()
    if team is None:
        return message('团队不存在')

    project = Project.objects.filter(team_belong_to=team, project_name=project_name, flag='normal').first()
    if project is None:
        return message('项目不存在')

    prototypes = Prototype.objects.filter(team_belong_to=team, project_belong_to=project)
    res = []
    for i in prototypes:
        if i.recyclable == False:
            res.append(prototype_information(i))
    return JsonResponse(res, safe=False)


@csrf_exempt
def get_prototype_content(request):
    project_name = request.POST.get('project_name')
    team_name = request.POST.get('team_name')
    prototype_name = request.POST.get('prototype_name')

    team = Team.objects.filter(team_name=team_name).first()
    if team is None:
        return message('团队不存在')

    project = Project.objects.filter(team_belong_to=team, project_name=project_name, flag='normal').first()
    if project is None:
        return message('项目不存在')

    prototype = Prototype.objects.filter(team_belong_to=team, project_belong_to=project,
                                         name=prototype_name).first()
    if prototype is None:
        return message('原型不存在')

    res = {
        'message': 'success',
        'content': prototype.content
    }
    return JsonResponse(res, safe=False)


@csrf_exempt
def swift_document_status(request):
    if request.method != 'POST':
        return message('fail')

    project_name = request.POST.get('project_name')
    team_name = request.POST.get('team_name')
    document_name = request.POST.get('document_name')

    team = Team.objects.filter(team_name=team_name).first()
    if team is None:
        return message('团队不存在')

    project = Project.objects.filter(team_belong_to=team, project_name=project_name, flag='normal').first()
    if project is None:
        return message('项目不存在')

    document = Document.objects.filter(team_belong_to=team, project_belong_to=project,
                                       document_name=document_name).first()
    if document is None:
        return message('文档不存在')

    if document.recyclable == False:
        document.recyclable = True
    else:
        document.recyclable = False
    document.save()
    project.update_time = datetime.datetime.now()
    project.save()
    return message('success')


@csrf_exempt
def swift_prototype_status(request):
    if request.method != 'POST':
        return message('fail')

    project_name = request.POST.get('project_name')
    team_name = request.POST.get('team_name')
    prototype_name = request.POST.get('prototype_name')

    team = Team.objects.filter(team_name=team_name).first()
    if team is None:
        return message('团队不存在')

    project = Project.objects.filter(team_belong_to=team, project_name=project_name, flag='normal').first()
    if project is None:
        return message('项目不存在')

    prototype = Prototype.objects.filter(team_belong_to=team, project_belong_to=project,
                                         name=prototype_name).first()
    if prototype is None:
        return message('原型不存在')

    if prototype.recyclable == False:
        prototype.recyclable = True
    else:
        prototype.recyclable = False
    prototype.save()
    return message('success')


@csrf_exempt
def swift_project_status(request):
    if request.method != 'POST':
        return message('fail')

    project_name = request.POST.get('project_name')
    team_name = request.POST.get('team_name')

    team = Team.objects.filter(team_name=team_name).first()
    if team is None:
        return message('团队不存在')

    project = Project.objects.filter(team_belong_to=team, project_name=project_name, flag='normal').first()
    if project is None:
        return message('项目不存在')

    if project.recyclable == False:
        project.recyclable = True
    else:
        project.recyclable = False
    project.save()
    return message('success')


@csrf_exempt
def get_recyclable_documents(request):
    project_name = request.POST.get('project_name')
    team_name = request.POST.get('team_name')

    team = Team.objects.filter(team_name=team_name).first()
    if team is None:
        return message('团队不存在')

    project = Project.objects.filter(team_belong_to=team, project_name=project_name, flag='normal').first()
    if project is None:
        return message('项目不存在')

    documents = Document.objects.filter(team_belong_to=team, project_belong_to=project)
    res = []
    for i in documents:
        if i.recyclable == True:
            res.append(document_information(i))
    return JsonResponse(res, safe=False)


@csrf_exempt
def get_recyclable_prototypes(request):
    project_name = request.POST.get('project_name')
    team_name = request.POST.get('team_name')

    team = Team.objects.filter(team_name=team_name).first()
    if team is None:
        return message('团队不存在')

    project = Project.objects.filter(team_belong_to=team, project_name=project_name, flag='normal').first()
    if project is None:
        return message('项目不存在')

    prototypes = Prototype.objects.filter(team_belong_to=team, project_belong_to=project)
    res = []
    for i in prototypes:
        if i.recyclable == True:
            res.append(prototype_information(i))
    return JsonResponse(res, safe=False)


@csrf_exempt
def get_recyclable_projects(request):
    team_name = request.POST.get('team_name')
    team = Team.objects.filter(team_name=team_name).first()
    projects = Project.objects.filter(team_belong_to=team, flag='normal')
    res = []
    for i in projects:
        if i.recyclable == True:
            res.append(project_information(i))
    return JsonResponse(res, safe=False)


@csrf_exempt
def keep_project(request):
    username = request.POST.get('username')
    team_name = request.POST.get('team_name')
    project_name = request.POST.get('project_name')

    user = User.objects.filter(username=username).first()
    if user is None:
        return message('用户不存在')
    team = Team.objects.filter(team_name=team_name).first()
    if team is None:
        return message('团队不存在')
    project = Project.objects.filter(team_belong_to=team, project_name=project_name, flag='normal').first()
    if project is None:
        return message('项目不存在')

    duplication = KeptProject.objects.filter(project=project, user=user).first()
    if duplication is None:
        new_kept_project = KeptProject(project=project, user=user)
        new_kept_project.save()
        return message('success')
    else:
        return message('项目已收藏')


@csrf_exempt
def cancel_keeping(request):
    username = request.POST.get('username')
    team_name = request.POST.get('team_name')
    project_name = request.POST.get('project_name')

    user = User.objects.filter(username=username).first()
    team = Team.objects.filter(team_name=team_name).first()
    project = Project.objects.filter(team_belong_to=team, project_name=project_name, flag='normal').first()

    kept_project = KeptProject.objects.filter(project=project, user=user).first()
    if kept_project is None:
        return message('项目不存在')
    else:
        kept_project.delete()
    return message('success')


@csrf_exempt
def kept_project_information(x):
    return {
        'team_belong_to': x.project.team_belong_to.team_name,
        'project_name': x.project.project_name,
        'created_time': x.project.created_time,
        'project_creator': x.project.project_creator.username,
        'description': x.project.description,
        'update_time': x.project.update_time
    }


@csrf_exempt
def get_kept_project(request):
    username = request.POST.get('username')
    user = User.objects.filter(username=username).first()
    if user is None:
        return message('用户不存在')
    kept_projects = KeptProject.objects.filter(user=user)
    res = []
    for i in kept_projects:
        if i.project.recyclable == False:
            res.append(kept_project_information(i))
    return JsonResponse(res, safe=False)


@csrf_exempt
def get_kept_project_of_certain_team(request):
    username = request.POST.get('username')
    team_name = request.POST.get('team_name')

    user = User.objects.filter(username=username).first()
    if user is None:
        return message('用户不存在')

    team = Team.objects.filter(team_name=team_name).first()
    if team is None:
        return message('团队不存在')

    kept_projects = KeptProject.objects.filter(user=user)
    res = []
    for i in kept_projects:
        if i.project.recyclable == False:
            if i.project.team_belong_to == team:
                res.append(kept_project_information(i))
    return JsonResponse(res, safe=False)


@csrf_exempt
def test(request):
    return message('yes')


@csrf_exempt
def get_all_notice(request):
    receiver = User.objects.get(username=request.POST.get('username'))
    all_notice = Notice.objects.filter(receiver=receiver).all()
    res = []
    for notice in all_notice:
        res.append(notice_to_content(notice))
    return JsonResponse(res, safe=False)


@csrf_exempt
def search_projects_in_team(request):
    team_name = request.POST.get('team_name')
    keywords = request.POST.get('keywords')

    team = Team.objects.filter(team_name=team_name).first()
    if team is None:
        return message('团队不存在')

    projects = Project.objects.filter(project_name__contains=keywords, flag='normal')

    res = []
    for i in projects:
        if i.team_belong_to == team:
            res.append(project_information(i))
    return JsonResponse(res, safe=False)


@csrf_exempt
def search_all_projects(request):
    keywords = request.POST.get('keywords')
    projects = Project.objects.filter(project_name__contains=keywords, flag='normal')
    res = []
    for i in projects:
        res.append(project_information(i))
    return JsonResponse(res, safe=False)


@csrf_exempt
def get_team_data(request):
    team_name = request.POST.get('team_name')
    team = Team.objects.filter(team_name=team_name).first()
    if team is None:
        return message('团队不存在')

    projects = Project.objects.filter(team_belong_to=team, flag='normal')
    res = []
    for project in projects:
        documents = Document.objects.filter(project_belong_to=project)
        document_names = []
        for document in documents:
            document_names.append(document.document_name)
        res.append({
            'project_name': project.project_name,
            'document_names': document_names
        })
    return JsonResponse(res, safe=False)


@csrf_exempt
def copy_project(request):
    origin_team_name = request.POST.get('origin_team_name')
    origin_project_name = request.POST.get('origin_project_name')
    destination_team_name = request.POST.get('destination_team_name')
    new_project_name = request.POST.get('new_project_name')
    username = request.POST.get('username')

    user = User.objects.filter(username=username).first()
    if user is None:
        return message('用户不存在')

    origin_team = Team.objects.filter(team_name=origin_team_name).first()
    if origin_team is None:
        return message('团队不存在')

    origin_project = Project.objects.filter(team_belong_to=origin_team, project_name=origin_project_name,
                                            flag='normal').first()
    if origin_project is None:
        return message('项目不存在')

    destination_team = Team.objects.filter(team_name=destination_team_name).first()
    if destination_team is None:
        return message('团队不存在')

    duplication = Project.objects.filter(project_name=new_project_name, team_belong_to=destination_team,
                                         flag='normal').first()
    if duplication is not None:
        if duplication.recyclable:
            return message('该项目在回收站中')
        return message('该项目已存在')

    new_project = Project(
        project_name=new_project_name,
        project_creator=user,
        team_belong_to=destination_team,
        created_time=datetime.datetime.now(),
        update_time=datetime.datetime.now(),
        description=origin_project.description,
        recyclable=False,
        flag='normal'
    )
    new_project.save()

    origin_docs = Document.objects.filter(project_belong_to=origin_project)
    for doc in origin_docs:
        new_doc = Document(
            document_name=doc.document_name,
            document_creator=user,
            created_time=datetime.datetime.now(),
            content=doc.content,
            project_belong_to=new_project,
            team_belong_to=destination_team,
            update_time=datetime.datetime.now(),
            recyclable=doc.recyclable,
            type=doc.type
        )
        new_doc.save()

    origin_prototypes = Prototype.objects.filter(project_belong_to=origin_project)
    for prototype in origin_prototypes:
        new_prototype = Prototype(
            name=prototype.name,
            creator=user,
            created_time=datetime.datetime.now(),
            content=prototype.content,
            project_belong_to=new_project,
            team_belong_to=destination_team,
            update_time=datetime.datetime.now(),
            recyclable=prototype.recyclable,
            type=prototype.type
        )
        new_prototype.save()

    return message('success')


@csrf_exempt
def delete_all_notice(request):
    receiver = User.objects.get(username=request.POST.get('username'))
    all_notice = Notice.objects.filter(receiver=receiver).all()
    all_notice.delete()
    return message('success')


@csrf_exempt
def get_team_default_data(request):
    team_name = request.POST.get('team_name')
    data_type = request.POST.get('data_type')

    team = Team.objects.filter(team_name=team_name).first()
    if team is None:
        return message('团队不存在')

    project = Project.objects.filter(team_belong_to=team, flag='abnormal', description=data_type,
                                     project_name=data_type).first()

    return JsonResponse(project_information(project))


@csrf_exempt
def get_projects_of_certain_user_in_team(request):
    team_name = request.POST.get('team_name')
    username = request.POST.get('username')

    team = Team.objects.filter(team_name=team_name).first()
    if team is None:
        return message('团队不存在')

    user = User.objects.filter(username=username).first()
    if user is None:
        return message('用户不存在')

    projects = Project.objects.filter(project_creator=user, team_belong_to=team, flag='normal', recyclable=False)
    res = []
    for i in projects:
        j = KeptProject.objects.filter(user=user, project=i).first()
        if j is None:
            res.append(project_information_not_kept(i))
        else:
            res.append(project_information_kept(i))
    return JsonResponse(res, safe=False)


@csrf_exempt
def get_sort_projects(request):
    username = request.POST.get('username')
    order_by = request.POST.get('order_by')
    team_name = request.POST.get('team_name')
    user = User.objects.filter(username=username).first()
    if user is None:
        return message('用户不存在')
    team = Team.objects.filter(team_name=team_name).first()
    if team is None:
        return message('团队不存在')
    projects = Project.objects.filter(team_belong_to=team, flag='normal').order_by('-update_time')
    res = []
    if order_by == 'creator':
        for i in projects:
            if i.project_creator != user:
                continue
            if i.recyclable == False:
                j = KeptProject.objects.filter(user=user, project=i).first()
                if j is not None:
                    res.append(project_information_kept(i))
                else:
                    res.append(project_information_not_kept(i))
        for i in projects:
            if i.project_creator == user:
                continue
            if i.recyclable == False:
                j = KeptProject.objects.filter(user=user, project=i).first()
                if j is not None:
                    res.append(project_information_kept(i))
                else:
                    res.append(project_information_not_kept(i))
    elif order_by == 'time':
        for i in projects:
            if i.recyclable == False:
                j = KeptProject.objects.filter(user=user, project=i).first()
                if j is not None:
                    res.append(project_information_kept(i))
                else:
                    res.append(project_information_not_kept(i))
    else:
        for i in projects:
            if i.recyclable == False:
                j = KeptProject.objects.filter(user=user, project=i).first()
                if j is not None:
                    res.append(project_information_kept(i))
        for i in projects:
            if i.recyclable == False:
                j = KeptProject.objects.filter(user=user, project=i).first()
                if j is None:
                    res.append(project_information(i))
    return JsonResponse(res, safe=False)


@csrf_exempt
def invite_with_link(request):
    team = Team.objects.filter(team_name=request.POST.get('team_name')).first()
    receiver = User.objects.filter(username=request.POST.get('username')).first()
    if receiver is None:
        return message('用户不存在')
    member = LinkBetweenTeamAndMember.objects.filter(team=team, team_member=receiver).first()
    if member is not None:
        return message('该用户已在团队中')
    new_team_member = LinkBetweenTeamAndMember(team=team, team_member=receiver, membership='staff')
    new_team_member.save()
    team_members = LinkBetweenTeamAndMember.objects.filter(team=team)
    for members in team_members:
        member = members.team_member
        new_notice = Notice(sender=receiver, receiver=member,
                            content=receiver.username + "加入了团队(" + team.team_name + ")",
                            team=team, send_time=datetime.datetime.now(), type='invite')
        new_notice.save()
    return message('success')


@csrf_exempt
def clear_recycle_bin(request):
    team_name = request.POST.get('team_name')
    team = Team.objects.filter(team_name=team_name).first()
    if team is None:
        return message('团队不存在')

    projects = Project.objects.filter(team_belong_to=team, recyclable=True)
    for i in projects:
        i.delete()
    return message('success')


@csrf_exempt
def get_recent_changed_projects(request):
    team_name = request.POST.get('team_name')
    team = Team.objects.filter(team_name=team_name).first()
    if team is None:
        return message('团队不存在')

    username = request.POST.get('username')
    user = User.objects.filter(username=username).first()
    if user is None:
        return message('用户不存在')

    projects = Project.objects.filter(team_belong_to=team, recyclable=False, flag='normal')
    res = []
    d1 = datetime.datetime.now()
    for i in projects:
        d2 = i.update_time
        delta = d1 - d2
        if delta.days < 2:
            j = KeptProject.objects.filter(user=user, project=i).first()
            if j is None:
                res.append(project_information_not_kept(i))
            else:
                res.append(project_information_kept(i))
    return JsonResponse(res, safe=False)
